package com.epam.productstore.validation.rules;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.epam.productstore.validation.ValidationResult;
import com.epam.productstore.validation.ValidationRule;

public class MaskRule implements ValidationRule {
	
	private final Pattern pattern;
	
	public MaskRule(String mask) {
		pattern = Pattern.compile(mask);
	}
	
	@Override
	public ValidationResult validate(String value) {
		Matcher matcher = pattern.matcher(value);
		boolean result = matcher.matches();
		return new ValidationResult(result, null);
	}

}
